package org.dreamwork.android.concurrent;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * Created by game on 2016/9/7
 */
public class NonUILooper {
    private static final ExecutorService service = Executors.newCachedThreadPool ();

    /**
     * 在独立线程中执行任务
     * @param runner 异步任务
     */
    public static void runInNonUIThread (Runnable runner) {
        service.execute (runner);
    }

    /**
     * 清除资源
     *
     * 应该在 Application 的 onDestroy 中调用该方法，以保证所有线程被正确停止
     */
    public static void shutdown () {
        service.shutdown ();
    }
}